package com.yulongtian.oneProblemEveryDay.month202212;

import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode.cn/problems/check-if-number-is-a-sum-of-powers-of-three/
 * 可
 *
 * @author yulongTian
 * @create 2022-12-09 11:02
 */
public class Test05 {
    public static void main(String[] args) {
        System.out.println(checkPowersOfThree(123456));

    }

    //0~14

    public static boolean checkPowersOfThree(int n) {
        int len = 16;
        List<Integer> threes = new ArrayList<>();
        for (int i = 0; i < len; i++) {
            threes.add((int) Math.pow(3, i));
        }

        while (n != 0) {

            for (int i = 0; i < len; i++) {
                if (n < threes.get(0)) {
                    return false;
                }
                if (n < threes.get(i)) {
                    n -= threes.get(i - 1);
                    threes.remove(i - 1);
                    break;
                }
            }
        }
        return true;
    }


}
